from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Edge()
driver.get('https://www.baidu.com')
driver.find_element(By.LINK_TEXT, '新闻').click()
# 新窗口切换
driver.switch_to.window(driver.window_handles[-1])
time.sleep(2)
driver.find_element(By.PARTIAL_LINK_TEXT, '小树苗').click()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(5)
# 滚动
# 滚动到任意像素
driver.execute_script('window.scrollTo(0,2000)')
time.sleep(3)
# 滚动到底部
driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')
time.sleep(3)
# 滚动到顶部
driver.execute_script('window.scrollTo(0,0)')
time.sleep(3)